﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using OnlineVideos.Common;
using Common.Library;
using System.ComponentModel;
using OnlineVideos.Data;
using Common;
using Common.Utilities;
using System.Windows.Controls.Primitives;
using OnlineVideos.Entities;

namespace OnlineVideos
{
    public partial class PersonProfileShows : UserControl
    {
        #region GlobalDeclaration
        private bool IsDataLoaded;
        #endregion

        #region Constructor
        public PersonProfileShows()
        {
            InitializeComponent();
            IsDataLoaded = false;
        }
        #endregion

        #region PageLoad
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IsDataLoaded == false)
                {

                    BackgroundHelper bwHelper = new BackgroundHelper();

                    bwHelper.AddBackgroundTask(
                                                (object s, DoWorkEventArgs a) =>
                                                {
                                                    a.Result = OnlineShow.GetPersonRelatedShows(AppSettings.PersonID);
                                                },
                                                (object s, RunWorkerCompletedEventArgs a) =>
                                                {
                                                    lbxFilmography.ItemsSource = (List<ShowList>)a.Result;

                                                }
                                              );

                    bwHelper.RunBackgroundWorkers();

                    IsDataLoaded = true;

                }
            }
            catch (Exception ex)
            {
                
                Exceptions.SaveOrSendExceptions("Exception in UserControl_Loaded Method In PersonProfileShows.cs file.", ex);
            }
        
        }
        #endregion

        #region Events
        private void lbxFilmography_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            

            if (lbxFilmography.SelectedIndex == -1)
                return;
            PageHelper.NavigateToDetailPage(AppResources.DetailPageName,  ((sender as Selector).SelectedItem as ShowList).ShowID.ToString());
            AppSettings.ShowID= ((sender as Selector).SelectedItem as ShowList).ShowID.ToString();

            lbxFilmography.SelectedIndex = -1;
        }
        #endregion
    }
}
